---
pagination_prev: null
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import ThemedImage from '@theme/ThemedImage';
import {RIG_VERSION} from "../../../src/constants/versions"
import CodeBlock from '@theme/CodeBlock';

# CI/CD with Rig
With the [Rig CLI](/overview/guides/getting-started#install-the-rig-cli) you can easily integrate Rig with any CI/CD system. 
In guide we will go through how use Rig specifically with [Github Actions](/overview/guides/ci-cd#github-actions) or [GitLab CI/CD pipelines](/overview/guides/ci-cd#gitlab-cicd-pipelines).

## Github Actions
In addition to using the CLI "as is" in your Github Actions workflows, we have a setup action that makes it even easier.

### Preparing variables

We recommend that you define the following variables to be available
for Github actions.

- `RIG_HOST` containing the full URL to your Rig API.
- `RIG_CLIENT_ID` containing the client ID of your service account.
- `RIG_CLIENT_SECRET` containing the client secret of your service account.
  This should be stored as a secret variable in Github.

For more information about how to set variables and secrets please refer to the
official Github documentation for
[configuration variables](https://docs.github.com/en/actions/learn-github-actions/variables)
and
[secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions).

### Setup Step

For easy access to the Rig CLI in any GitHub Actions workflow, use our rig
setup action `rigdev/setup-rig@v1`:

<CodeBlock language="yaml">
{`jobs:
  deploy:
    steps:
      # Ensure that the rig CLI is installed and that the service account is
      # activated. This will enable you to use the CLI on behalf of the service
      # account.
      - name: Setup Rig
        uses: rigdev/setup-rig@v1
        with:
          # specify what version of the rig CLI you need. If left empty we use
          # the latest release.
          version: ${RIG_VERSION}
          host: \${{ vars.RIG_HOST }}
          client-id: \${{ vars.CLIENT_ID }}
          client-secret: \${{ secrets.CLIENT_SECRET }}
      # With the CLI installed and service account activated you can use the
      # CLI to send commands to the Rig API.
      - run: |
          rig deploy ...`}
</CodeBlock>

Now that you are able to run the `rig` CLI you can either checkout our general
documentation about [using the CLI in CI/CD systems](/operator-manual/ci-cd#deploying-changes) or read through the below
example.

### Example workflow: Build and deploy docker image

This example will show a full GitHub Actions workflow which builds a docker
image, and deploys it using the `rig` CLI.

In the workflow we will go through the following steps

1. Build a Docker image from a new commit
2. Push that Docker image GitHub container registry
3. Deploy the image in to a capsule named the same as the repository in the rig
   project 'my-project' for the production environment.

<CodeBlock language="yaml">
{`on: [push]

jobs:
  build-and-deploy:
    runs-on: ubuntu
    env:
      IMAGE_NAME: "ghcr.io/\${{ github.repository_owner }}/\${{ github.repository }}:\${{ github.sha }}"
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Login to GitHub container registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: \${{ github.actor }}
          password: \${{ secrets.GITHUB_TOKEN }}

      - name: Build and push
        uses: docker/build-push-action@v5
        with:
          push: true
          tags: \${{ env.IMAGE_NAME }}

      - name: Setup Rig
        uses: rigdev/setup-rig@v1
        with:
          version: ${RIG_VERSION}
          host: \${{ vars.RIG_HOST }}
          client-id: \${{ vars.RIG_CLIENT_ID }}
          client-secret: \${{ secrets.RIG_CLIENT_SECRET }}

      - name: Deploy Capsule to production
        run: |
          rig deploy \${{ github.repository }} \\
            --project my-project \\
            --environment production \\
            --image \${{ env.IMAGE_NAME }}`}
</CodeBlock>


## GitLab CI/CD Pipelines

When using GitLab, we recommend that the `rig` CLI is used in its
docker image format.

### Preparing variables

We recommend that you define the following variables to be available
for pipelines.

- `RIG_HOST` containing the full URL to your Rig API.
- `RIG_CLIENT_ID` containing the client ID of your service account.
- `RIG_CLIENT_SECRET` containing the client secret of your service account.

For more information about how to set variables please refer to the [GitLab
CI/CD Variables](https://docs.gitlab.com/ee/ci/variables/) documentation.

### Using `rig` CLI in a job

The easiest way to use the Rig CLI in your GitLab jobs is by running your job
in our CLI image. See the following for a simple example of a GitLab Pipeline.

<CodeBlock language="yaml">
{`deploy:
  image: ghcr.io/rigdev/rig:` + RIG_VERSION + `
  script:
    # Activate the service account from RIG_CLIENT_ID, RIG_CLIENT_SECRET and
    # RIG_HOST. This will enable you to use the CLI on behalf of the service
    # account.
    - rig auth activate-service-account -H $RIG_HOST
    # When the service account is activated you can go ahead and issue commands
    # on the CLI.
    - rig capsule deploy ...`}
</CodeBlock>

Now that you know how to run the `rig` CLI in GitLab. You can go ahead and
checkout our documentation for how to effectively [use the CLI in CI Systems](/operator-manual/ci-cd#deploying-changes).